<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>异步请求</title>
</head>
<body>
    
</body>
</html>

<script>
    function ajax(url,resolve,reject){
        let xhr = new XMLHttpRequest();
        xhr.open('GET',url);
        xhr.send();
        xhr.onload = function(){
            if(this.status == 200){
                resolve(JSON.parse(this.response));
            }else{
                reject(this);
            }
        }
    }

    ajax("http://localhost:8888/promise/php/user.php?name=向军",user => {
        ajax(`http://localhost:8888/promise/php/houdunren.php?id=${user.id}`,response => {
            console.log(response);
        });
    });
</script>